import {
  api,
  util
} from '../../../js/util';
import {
  CollectData
} from '../../../js/modules/dtcollect';
const componentBehavior = require('../../../js/common/ComponentBehavior')

Component({
  behaviors: [componentBehavior],
  lifetimes: {
    attached() {
      // 在组件实例进入页面节点树时执行
      //console.log("begin attached")
    },
    detached() {
      // 在组件实例被从页面节点树移除时执行
    },
  },
  /**
   * 组件的属性列表
   */
  properties: {

    pageKey: {
      value: "",
      type: String
    },
    isDefaultLoad: {
      value: true,
      type: Boolean
    },
    pageInfo:{
      value:null,
      type:Object
    }
  },
  pageLifetimes: {
    // 组件所在页面的生命周期函数
    show() {
      if (this.data.isDefaultLoad) {
        this.onPageRequst();
      }
    },
    hide() {}
  },
  /**
   * 组件的初始数据
   */
  data: {},
  this_timer_id: null,
  /**
   * 组件的方法列表
   */
  methods: {
    onPageRequst() {
      var that = this;
      if (typeof that.this_timer_id != null) {
        clearTimeout(that.this_timer_id);
      }
      that.this_timer_id = setTimeout(function() {
        new CollectData({
          pageKey: that.data.pageKey
        }).pageRequest(that.data.pageInfo);
      }, 200);

    }
  }
})